﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.EditorExt;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.NetworkAnalysis;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;

namespace DIWAGIS.ApplicationLayer.BanDo
{
    public partial class frmEdittingSnapOption : Form
    {
        //public frmEdittingSnapOption()
        //{
        //    InitializeComponent();
        //}
        ILayer m_TargetLayer;
        IMapControl4 m_MapControl;
        DataTable tblResult;
        private IEngineEditor m_editor;
        public frmEdittingSnapOption(IEngineEditor editor, ILayer targetLayer, IMapControl4 mapControl)
        {
            InitializeComponent();
            m_TargetLayer = targetLayer;
            m_MapControl = mapControl;
            m_editor = editor;
        }
        private IEngineEditor editor;
        private IEngineEditLayers editLayers;
        private IEngineSnapEnvironment snapEnvironment;

        private void cmdDongY_Click(object sender, EventArgs e)
        {
            try
            {
                DIWAGIS.Class.Editing editing = new DIWAGIS.Class.Editing();
                editLayers = m_editor as IEngineEditLayers;
                snapEnvironment = m_editor as IEngineSnapEnvironment;
                editLayers.SetTargetLayer(m_TargetLayer as IFeatureLayer, 0);
                editing.SetSnapEnvironment(m_editor, tblResult, double.Parse(txtKhoangCach.Text), m_MapControl);
                this.Close();
            }
            catch (Exception ex)
            {
               // PublicProject.clsStaticFunctions.ThongBaoLoi(ex);
            }
        }

        private void frmEdittingSnapOption_Load(object sender, EventArgs e)
        {

            try
            {
            
                editLayers = m_editor as IEngineEditLayers;
                snapEnvironment = m_editor as IEngineSnapEnvironment;
                editLayers.SetTargetLayer(m_TargetLayer as IFeatureLayer, 0);


                tblResult = new DataTable();
                //Tạo table
                DataColumn colLayerName = new DataColumn("LayerName", typeof(string));
                DataColumn colVertex = new DataColumn("Vertex", typeof(bool));
                DataColumn colEdge = new DataColumn("Edge", typeof(bool));
                DataColumn colEndPoint = new DataColumn("EndPoint", typeof(bool));
                tblResult.Columns.Add(colLayerName);
                tblResult.Columns.Add(colVertex);
                tblResult.Columns.Add(colEdge);
                tblResult.Columns.Add(colEndPoint);
                double tolerance = 0;

                DIWAGIS.Class.Editing editing = new DIWAGIS.Class.Editing();
                editing.GetSnapEnvironment(m_editor, ref tblResult, ref tolerance, m_MapControl);
                dataGridView1.DataSource = tblResult;
                txtKhoangCach.Text = tolerance.ToString();
            }
            catch (Exception ex)
            {
                //PublicProject.clsStaticFunctions.ThongBaoLoi(ex);
            }
        }

        private void cmdDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

}
